const userModel = require('../model/userModel')

let loginMsg = [
  '',
  '登录或密码不正确',
  '请先登录，再访问',
  '欢迎再次登录'
]

module.exports = {

  index(req, res) {
    let msg = loginMsg[req.query.type]
    res.render('admin/login.html', { msg })
  },
  async login(req, res) {
    let { username, password } = req.body
    let bool = await userModel.checkuserlogin(username, password)
    if (bool) {
      // 写入session
      req.session['username'] = username
      res.redirect('/admin/index')
    } else {
      res.redirect('/admin/login?type=1')
    }
  }


}

